package com.yh.csx.business.core.controller;

import com.yh.csx.business.api.entity.CommonResponse;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.Callable;

@Slf4j
public abstract class BsfController {

    public <T> CommonResponse<T> visit(Runnable runnable) {
        try {
            runnable.run();
            return CommonResponse.success();
        } catch (Throwable e) {
            log.error("", e);
            return CommonResponse.error(e);
        }
    }

    public <T> CommonResponse<T> visit(Callable<T> callable) {
        try {
            return CommonResponse.success(callable.call());
        } catch (Throwable e) {
            log.error("", e);
            return CommonResponse.error(e);
        }
    }
}
